package engine;

import java.awt.Color;
import java.awt.Point;
import java.util.ArrayList;

public class Vertex
{
   private Color c;
   private ArrayList<Edge> edges = new ArrayList<Edge>();
   private String id;
   private String name;
   private int recent = 0;
   private int status = 0;
   private ArrayList<Edge> visitedList = new ArrayList<Edge>();
   private int xPos, yPos;

   public Vertex(int x, int y, String name)
   {
      this.name = name;
      xPos = x;
      yPos = y;
      setStatus(0);
      id = ("" + x + "" + y);
   }

   public Vertex(int x, int y, String name, int status)
   {
      this.name = name;
      xPos = x;
      yPos = y;
      setStatus(status);
      id = ("" + x + "" + y);

   }

   public void activeAllConnectedEdges()
   {
      for (int i = 0; i < edges.size(); i++)
         if (edges.get(i).getStatus() == 0)
            edges.get(i).setStatus(1);
   }

   public void addEdge(Edge e)
   {
      edges.add(e);
   }

   public void addVisitedList(Edge e)
   {
      visitedList.add(e);
   }

   public ArrayList<Edge> getAllEdges()
   {
      return edges;
   }

   public Color getColor()
   {
      return c;
   }

   public String getColorToString()
   {
      if (c == Color.green)
         return "green";
      else if (c == Color.blue)
         return "blue";
      else if (c == Color.red)
         return "red";
      else if (c == Color.black)
         return "black";
      else if (c == Color.white)
         return "white";
      else
         return null;

   }

   public String getName()
   {
      return name;
   }

   public int getNumOfConnectEdge()
   {
      return edges.size();
   }

   public Point getPoint()
   {
      return new Point(xPos, yPos);
   }

   public int getRecentStatus()
   {
      return recent;
   }

   public int getStatus()
   {
      return status;
   }

   public String getuID()
   {
      return id;
   }

   public String getXtoString()
   {
      return "" + xPos;
   }

   public String getYtoString()
   {
      return "" + yPos;
   }

   public boolean isAllEdgeStatusEqual(int x)
   {
      for (int i = 0; i < edges.size(); i++)
         if (edges.get(i).getStatus() != x)
            return false;
      return true;
   }

   public boolean isEdgeExist(Edge e)
   {
      return edges.equals(e);
   }

   public boolean isExistInVisitedList(Edge e)
   {

      for (int i = 0; i < visitedList.size(); i++)
         if (visitedList.get(i).equals(e))
            return true;
      return false;
   }

   public boolean isVisited()
   {
      if (status == 3)
         return true;
      return false;
   }

   public void printEdgesStatus()
   {
      System.out.println("Node Name is " + name);
      for (int i = 0; i < edges.size(); i++)
         System.out.println("Edge " + edges.get(i).getWeight() + " Status "
               + edges.get(i).getStatus());
   }

   public boolean remove(Edge e)
   {
      return edges.remove(e);
   }

   public void resetVisitList()
   {
      visitedList = new ArrayList<Edge>();

   }

   public void setAllEdgesStatus(int s)
   {
      for (int i = 0; i < edges.size(); i++)
         edges.get(i).setStatus(s);
   }

   public void setAllEdgeStatusFromTo(int from, int to)
   {
      for (int i = 0; i < edges.size(); i++)
         if (edges.get(i).getStatus() == from)
            edges.get(i).setStatus(to);
   }

   public void setColor(Color c)
   {
      this.c = c;
   }
   public void setName(String name)
   {
      this.name = name;
   }

   public void setPoint(Point p)
   {
      xPos = p.x;
      yPos = p.y;
   }

   public void setPosition(int x, int y)
   {
      xPos = x;
      yPos = y;
   }

   public void setStatus(int s)
   {
      if (status != s)
         recent = status;
      status = s;
      if (status == 2)
         c = Color.green;
      else
         c = Color.white;
   }

   public int xPos()
   {
      return xPos;
   }

   public int yPos()
   {
      return yPos;
   }
}
